package demo5;

public class Account {
    private int ID;
    private String name;
    private float balance;

    public int getID() {
        return ID;
    }

    public void setID(int ID) {
        this.ID = ID;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public float getBalance() {
        return balance;
    }

    public void setBalance(float balance) {
        this.balance = balance;
    }

    public Account(int ID, String name, float balance) {
        this.ID = ID;
        this.name = name;
        this.balance = balance;
    }

    public int withDraw(float m) throws RuntimeException {
        if (this.balance >= m) {
            balance = balance - m;
            return 1;
        } else {
            throw new RuntimeException("余额不足，快充钱！！！");
        }
    }

    public void saving(float m) {
        balance = balance + m;
    }

    public void showMe() {
        System.out.println("姓名：" + this.name + "   " + "账户余额：" + this.balance);
    }

    public void transfer(Account a, Account b, float m) throws RuntimeException {
        if (a.withDraw(m) == 1) {
            b.saving(m);
        }
    }
}
